# -*- coding: utf-8 -*-
class Product:
    def __init__(self, product_id, name, price, stock):
        self.product_id = product_id
        self.name = name
        self.price = price
        self.stock = stock


products = []


def add_product():
    try:
        product_id = input("输入商品ID：")
        # 检查ID是否已存在
        if any(p.product_id == product_id for p in products):
            print("错误：该ID已存在！")
            return

        name = input("输入商品名称：").strip()
        price = float(input("输入商品价格："))
        stock = int(input("输入初始库存："))

        if price < 0 or stock < 0:
            print("错误：价格和库存不能为负数！")
            return
    except ValueError:
        print("输入格式错误！")
        return

    new_product = Product(product_id, name, price, stock)
    products.append(new_product)
    print("商品添加成功！")


def display_products():
    print("\n商品列表：")
    print(f"{'ID':<5}{'名称':<10}{'价格':<8}{'库存':<6}")
    for p in products:
        print(f"{p.product_id:<5}{p.name:<10}{p.price:<8.2f}{p.stock:<6}")


def find_product(product_id):
    for p in products:
        if p.product_id == product_id:
            return p
    return None


def update_product():
    # ... 修改商品信息的代码 ...
    print("商品信息已更新")


def delete_product():
    # ... 删除商品代码 ...
    print("商品已删除")


def adjust_stock():
    # ... 库存调整代码 ...
    print("库存已更新")


def show_menu():
    while True:
        print("\n商品管理系统")
        print("1. 添加商品")
        print("2. 显示所有商品")
        print("3. 修改商品信息")
        print("4. 删除商品")
        print("5. 调整库存")
        print("6. 退出系统")

        choice = input("请选择操作：")
        # ... 处理用户选择的代码 ...


if __name__ == "__main__":
    show_menu() 